/*
   Copyright (c) [2023] [魔凤啸天]
   [MFUI] is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
            http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details.  
*/
#include "texturerect.hpp"

namespace MFUI{
	TextureRect::~TextureRect(){}
	TextureRect::TextureRect(SDL_Texture* texture,Uint8 alpha):texture(texture),
	alpha(alpha){src.x=0,src.y=0;}
	void TextureRect::setalpha(Uint8 a){
		if(alpha!=a){
			alpha=a;
			redraw=true;
			notifyparent();
		}
	}
	Uint8 TextureRect::getalpha()const{return alpha;}
	TextureRect::TextureRect(SDL_Texture* texture,SDL_Rect& src,Uint8 alpha):
	texture(texture),src(src),alpha(alpha){}
	void TextureRect::draw(Renderer* r,bool updatecache){
		_draw(r,updatecache);
		SDL_SetTextureAlphaMod(texture,alpha);
		r->copyF(texture,&src,&rect);
		redraw=false;
	}
	void TextureRect::settexture(SDL_Texture* texture){
		this->texture=texture;
		int w,h;
		SDL_QueryTexture(texture,nullptr,nullptr,&w,&h);
		src.w=w,src.h=h;
		redraw=true;
		notifyparent();
	}
	void TextureRect::settexture(SDL_Texture* texture,SDL_Rect& src){
		this->texture=texture;
		this->src=src;
		redraw=true;
		notifyparent();
	}
	SDL_Texture* TextureRect::gettexture()const{return texture;}
	void TextureRect::setsrc(SDL_Rect& src){
		this->src=src;
		redraw=true;
		notifyparent();
	}
	const SDL_Rect& TextureRect::getsrc()const{return src;}
}